home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / games / fagot.lzh / FAGOT.c next >
C/C++ Source or Header  |  1995-09-14  |  2KB  |  75 lines

  1. /*
  2.  * FAGOT - Fantasia-Aiheisten Good Nimien Oiva Tuottaja
  3.  * by K.Veijalainen <veijalai@cc.lut.fi>
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <time.h>
  10.  
  11. #define VERSION "v1.0"
  12.  
  13. #define BUFFER_SIZE   1024
  14. #define MAX_SYLLABLES 1024
  15.  
  16. int main(int argc, unsigned char **argv) {
  17.     /* Temp storage for strings.*/
  18.     unsigned char buffer[BUFFER_SIZE],*t;
  19.     /* Syllables.*/
  20.     unsigned char *syllables[MAX_SYLLABLES];
  21.     int name_n,x,l,n1,n2,n3,sc[3];
  22.     
  23.     srandom((unsigned int)time(NULL));
  24.     
  25.     /* Blah. */
  26.     if(argc!=2)
  27.       printf("Usage: %s <number_of_names>\n",argv[0]);
  28.     else {
  29.         name_n=atoi(argv[1]);
  30.         if(name_n<1)
  31.           printf("You must ask for at least one name.\n");
  32.         else {
  33.             x=l=sc[0]=sc[1]=sc[2]=0;
  34.             /* Read the syllables.*/
  35.             while(gets(buffer)) {
  36.                 /* asdasd? dsadsad. asdasdsad! */
  37.                 if(buffer[0]=='-')
  38.                   sc[++x]=l;
  39.                 else {
  40.                     /* Malloc space for the string.*/
  41.                     t=malloc(strlen(buffer)+1);
  42.                     strcpy(t,buffer);
  43.                     /* pointer array reblah...*/
  44.                     syllables[l++]=t;
  45.                     /* inc amount of n1/n2/n3 */
  46.                     switch(x) {
  47.                      case 0:
  48.                         ++n1;
  49.                         break;
  50.                      case 1:
  51.                         ++n2;
  52.                         break;
  53.                      case 2:
  54.                         ++n3;
  55.                     }
  56.                 }
  57.             }
  58.             
  59.             /* Now make the names out of the syllables.*/
  60.             for(x=0;x<name_n;x++) {
  61.                 /* Clear buffer.*/
  62.                 buffer[0]=0;
  63.                 /* 1 */
  64.                 printf("%s",syllables[random()%n1]);
  65.                 /* 2 */
  66.                 if(random()%100<60)
  67.                   printf("%s",syllables[sc[1]+random()%n2]);
  68.                 /* 3 */
  69.                 printf("%s\n",syllables[sc[2]+random()%n3]);
  70.             }
  71.         }
  72.     }
  73.     exit(0);
  74. }
  75.